import Toast from '@vant/weapp/dist/toast/toast'
import Dialog from '@vant/weapp/dist/dialog/dialog'
import Notify from '@vant/weapp/dist/notify/notify'

/**
 * Vant Weapp 组件库配置和工具函数
 */

// Toast 提示配置
export const showToast = (options) => {
  if (typeof options === 'string') {
    options = { message: options }
  }
  Toast({
    duration: 2000,
    type: 'text',
    ...options
  })
}

// Dialog 对话框配置
export const showDialog = (options) => {
  return Dialog(options)
}

// Notify 通知配置
export const showNotify = (options) => {
  if (typeof options === 'string') {
    options = { message: options }
  }
  Notify(options)
}

// 主题色配置
export const themeConfig = {
  primaryColor: '#4B0082', // 主题紫色
  successColor: '#07c160',
  dangerColor: '#ee0a24',
  warningColor: '#ff976a',
  infoColor: '#1989fa'
}

// Vant 组件默认配置
export const vantConfig = {
  // Button 按钮默认配置
  button: {
    type: 'primary',
    size: 'normal',
    round: true
  },

  // Field 输入框默认配置
  field: {
    clearable: true,
    border: true
  },

  // Cell 单元格默认配置
  cell: {
    border: true,
    clickable: true
  },

  // Card 卡片默认配置
  card: {
    lazy: true
  },

  // Tab 标签页默认配置
  tabs: {
    animated: true,
    swipeable: true,
    sticky: true
  },

  // Popup 弹出层默认配置
  popup: {
    round: true,
    closeable: true,
    closeOnClickOverlay: true
  },

  // Search 搜索框默认配置
  search: {
    shape: 'round',
    clearable: true,
    placeholder: '请输入搜索关键词'
  },

  // Uploader 上传默认配置
  uploader: {
    maxCount: 9,
    maxSize: 10 * 1024 * 1024, // 10MB
    previewSize: 80,
    accept: 'image'
  },

  // DatetimePicker 时间选择器默认配置
  datetimePicker: {
    type: 'datetime',
    minDate: new Date(2020, 0, 1).getTime(),
    maxDate: new Date(2030, 11, 31).getTime()
  }
}

// 导出所有配置
export default {
  showToast,
  showDialog,
  showNotify,
  themeConfig,
  vantConfig
}